/*
 * @Date: 2021-11-30 15:42:07
 * @LastEditors: 春贰
 * @Desc:
 * @LastEditTime: 2023-11-28 15:54:34
 * @FilePath: \web\vite.config.js
 */ 
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue"; 
import path from "path";
const plugins = [vue()];

 

const config = ({ mode }) => {
  // console.log(loadEnv(mode, process.cwd()).VITE_PORT);
  return defineConfig({
    plugins,
    base: process.env.ELECTRON == "true" ? "./" : "",
    server: {
      host: "0.0.0.0",
      port: loadEnv(mode, process.cwd()).VITE_PORT
    },
    resolve: {
      extensions: [".js", ".vue", ".json"],
      alias: {
        "@": path.resolve(__dirname, "src") 
      }
    },
    // 开启less支持
    css: {
      preprocessorOptions: {
        less: {
          javascriptEnabled: true
        }
      }
    },
    hmr: {
      overlay: true
    },

    build: {
      minify: "terser",
      chunkSizeWarningLimit: 1500, // 单个文件大小警告
      //清除console
      terserOptions: {
        compress: {
          drop_console: false,
          drop_debugger: true
        }
      },
      rollupOptions: {
        // output:{
        //   manualChunks(id){ // 分包
        //     if(id.includes('node_modules')){
        //       return id.toString().split('node_modules/')[1].split('/')[0].toString();
        //     }
        //   }
        // }
      }
    },
    optimizeDeps: {
      exclude: ["@antv/x6-vue-shape"] //这玩意一定要加，因为x6 是commonjs
    },
    define: {
      // 定义全局变量 版本号
      __VERSION__: JSON.stringify(process.env.npm_package_version)
    }
  });
};
export default config;
